<?php

include("./config/session-action.php");
include("./config/config.inc.php");
include("./config/QuickMySQL.php");
/*防毒墙用户的操作*/
class CEmailListAction extends JsonBase
{
	/*添加用户*/
	function OnAddEmail(){
		$addr = str_replace("'", "''", (isset($_POST['addr']))?$_POST['addr']:'');
		$name = str_replace("'", "''", (isset($_POST['name']))?$_POST['name']:'');
		$smtp = str_replace("'", "''", (isset($_POST['smtp']))?$_POST['smtp']:'');
		$user = str_replace("'", "''", (isset($_POST['user']))?$_POST['user']:'');
		$pwd = str_replace("'", "''", (isset($_POST['pwd']))?$_POST['pwd']:'');
		$port = (isset($_POST['port']))?(int)$_POST['port']:25;
		$sql = "insert into t_email_list(addr, name, smtp, user, pwd, port) values("
			. "'{$addr}', '{$name}', '{$smtp}', '{$user}', '{$pwd}', {$port})";
		if( QuickMySQL::quickExecute($sql) ){
			$this->json["success"] = true;
			$this->json["msg"] = "添加成功";
		} else {
			$this->json["msg"] = "添加失败";
		}
	}
	/* 删除用户 */
	function OnDeleteEmail(){
		$id = (isset($_POST['id']))?(int)$_POST['id']:0;
		$sql = "delete from t_email_list where id={$id}";
		if( QuickMySQL::quickExecute($sql) ){
			$this->json["success"] = true;
			$this->json["msg"] = "删除成功";
		} else {
			$this->json["msg"] = "删除失败";
		}
	}
	/* 修改用户 */
	function OnModityEmail(){
		$id = (isset($_GET['id']))?(int)$_GET['id']:0;
		$addr = str_replace("'", "''", (isset($_POST['addr']))?$_POST['addr']:'');
		$name = str_replace("'", "''", (isset($_POST['name']))?$_POST['name']:'');
		$smtp = str_replace("'", "''", (isset($_POST['smtp']))?$_POST['smtp']:'');
		$user = str_replace("'", "''", (isset($_POST['user']))?$_POST['user']:'');
		$pwd = str_replace("'", "''", (isset($_POST['pwd']))?$_POST['pwd']:'');
		$port = (isset($_POST['port']))?(int)$_POST['port']:25;
		$sql = "update t_email_list set addr='{$addr}', name='{$name}', smtp='{$smtp}'"
			. " , user='{$user}', pwd='{$pwd}', port={$port} where id={$id}";
		if( QuickMySQL::quickExecute($sql) ){
			$this->json["success"] = true;
			$this->json["msg"] = "修改成功";
		} else {
			$this->json["msg"] = "修改失败";
		}
	}
}

$cc = new CEmailListAction();
?>